﻿var app = angular.module('groceryApp', [
    'ngRoute',
    'angularMoment'
]);

app.config(['$routeProvider', '$httpProvider', function ($routeProvider, $httpProvider) {
    $routeProvider.when('/', {
        templateUrl: '/app/views/WelcomeView.html',
        controller: 'WelcomeController'
    })
    .when('/groceries', {
        templateUrl: '/app/views/GroceryListView.html',
        controller: 'GroceryController'
    })
    .when('/login', {
        templateUrl: '/app/views/LoginView.html',
        controller: 'LoginController'
    })
    .when('/admin', {
        templateUrl: '/app/views/AdminView.html',
        controller: 'AdminController'
    })
    .when('/newitem', {
        templateUrl: '/app/views/NewItemView.html',
        controller: 'NewItemController'
    });

    $httpProvider.interceptors.push('AuthService');
}]);


app.filter('sumOfValue', function () {
    return function (data, key) {
        if (typeof (data) === 'undefined' && typeof (key) === 'undefined') {
            return 0;
        }
        var sum = 0;
        for (var i = 0; i < data.length; i++) {
            sum = sum + data[i][key];
        }
        return sum;
    }
})
app.filter('totalSumPriceQty', function () {
    return function (data, key1, key2) {
        debugger;
        if (typeof (data) === 'undefined' && typeof (key1) === 'undefined' && typeof (key2) === 'undefined') {
            return 0;
        }
        var sum = 0;
        for (var i = 0; i < data.length; i++) {
            sum = sum + (data[i][key1] * data[i][key2]);
        }
        return sum;
    }
})